package com.ddwl.message.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.MySqlUtil;
import com.ddwl.message.mapper.ShopMessageUserMapper;
import com.ddwl.message.model.ShopMessageUser;
import com.ddwl.message.model.ShopMessageUserList;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Repository
public class ShopMessageUserDao extends TkDao<ShopMessageUserMapper, ShopMessageUser> {

    @Resource
    private ShopMessageUserMapper shopMessageUserMapper;

    public List<ShopMessageUserList> getListByShopId(String shopId) {
        return shopMessageUserMapper.getListByShopId(shopId);
    }

    public void updateReadStatus(String shopId,String messageId) {
        shopMessageUserMapper.updateReadStatus(shopId,messageId);
    }

    public List<ShopMessageUser> getList(ShopMessageUser messageUser) {
        Example example = getExample();
        example.and().andEqualTo("messageInfoId", messageUser.getMessageInfoId())
                .andEqualTo("shopId", messageUser.getShopId())
                .andLike("userPhone", MySqlUtil.rightLike(messageUser.getUserPhone()))
                .andEqualTo("readStatus", messageUser.getReadStatus())
                .andLike("userId", messageUser.getUserId());
        return shopMessageUserMapper.selectByExample(example);
    }

    public void deleteByMessageId(String messageId) {
        shopMessageUserMapper.deleteByMessageId(messageId);
    }


    public void insertByList(List<ShopMessageUser> list) {
        shopMessageUserMapper.insertByList(list);
    }

    public List<ShopMessageUserList> getHasRead(ShopMessageUser messageUser){
        return shopMessageUserMapper.getHasRead(messageUser);
    }

    public void changeId(Map<String, String> map) {
        shopMessageUserMapper.changeId(map);
    }

    public void changeMessageInfoId(Map<String, String> map) {
        shopMessageUserMapper.changeMessageInfoId(map);
    }

    public List<ShopMessageUser> getAll() {
        Example example = new Example(ShopMessageUser.class);
        return shopMessageUserMapper.selectByExample(example);
    }
}
